package com.withmiku.world.user.repository;

import com.withmiku.world.user.entity.PostLike;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

public interface PostLikeRepository extends JpaRepository<PostLike, Long> {
//    Optional<PostLike> findByPostIdAndUserId(Long postId, Long userId);

    @Transactional
    @Modifying
    @Query("DELETE FROM PostLike l WHERE l.userId = :userId AND l.postId = :postId")
    void deleteByPostIdAndUserId(@Param("postId") Long postId, @Param("userId") Long userId);

    boolean existsByPostIdAndUserId(Long postId, Long userId);

//    long countByPostId(Long postId);
}
